package edu.gdkm.dao;

import edu.gdkm.pojo.ExportHistory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExportHistoryDao {

    // 根据ID查询
    @Select("SELECT * FROM ExportHistory WHERE export_id = #{exportId}")
    ExportHistory selectById(Integer exportId);

    // 根据用户ID查询
    @Select("SELECT * FROM ExportHistory WHERE user_id = #{userId} ORDER BY export_date DESC")
    List<ExportHistory> selectByUserId(Integer userId);
    
    // 根据简历ID查询
    @Select("SELECT * FROM ExportHistory WHERE resume_id = #{resumeId} ORDER BY export_date DESC")
    List<ExportHistory> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM ExportHistory")
    List<ExportHistory> selectAll();

    // 新增
    @Insert("INSERT INTO ExportHistory(resume_id, user_id, export_date, file_format, file_size, file_path) " +
            "VALUES(#{resumeId}, #{userId}, #{exportDate}, #{fileFormat}, #{fileSize}, #{filePath})")
    @Options(useGeneratedKeys = true, keyProperty = "exportId")
    int insert(ExportHistory exportHistory);

    // 更新
    @Update("UPDATE ExportHistory SET resume_id = #{resumeId}, user_id = #{userId}, export_date = #{exportDate}, " +
            "file_format = #{fileFormat}, file_size = #{fileSize}, file_path = #{filePath} " +
            "WHERE export_id = #{exportId}")
    int update(ExportHistory exportHistory);

    // 删除
    @Delete("DELETE FROM ExportHistory WHERE export_id = #{exportId}")
    int delete(Integer exportId);
}
    